<?php
function edits( )
{
				global $db;
				$db->query( "SELECT * FROM tun2_member WHERE id=".$_GET['id'] );
				if ( $db->next_record( ) )
				{
								echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n<form action=\"Admin_Member.php?Action=edit\" method=\"post\" onSubmit=\"return Validator.Validate(this,3)\">\r\n<input name=\"password3\" type=\"hidden\" value=\"";
								echo $db->Record['password'];
								echo "\"/>\r\n  <input name=\"id\" type=\"hidden\" value=\"";
								echo $db->Record['id'];
								echo "\"/>\r\n  <tr>\r\n    <td width=\"15%\" align=\"right\">会员账号：</td>\r\n    <td> <input name=\"user\" type=\"text\" value=\"";
								echo $db->Record['user'];
								echo "\" size=\"20\" dataType=\"LimitB\" min=\"3\" max=\"20\" msg=\"用户名必须在3,20个字节之内\"/></td>\r\n    </tr>\r\n <tr>\r\n    <td align=\"right\"> 密码：</td>\r\n    <td><input  name=\"password\" type=\"password\" value=\"\" size=\"40\"/>*留空则不修改密码</td>\r\n    </tr>\r\n  <tr>\r\n    <td align=\"right\">重复密码： </td>\r\n    <td><input  name=\"password2\" type=\"password\" value=\"\" size=\"40\" dataType=\"Repeat\" to=\"password\" msg=\"两次输入的密码不一致\"/></td>\r\n  </tr>\r\n<tr><td align=\"right\">邮箱地址： </td><td><input  name=\"email\" type=\"text\" value=\"";
								echo $db->Record['email'];
								echo "\" size=\"40\" /></td></tr><tr><td align=\"right\">积分：</td><td><input  name=\"points\" type=\"text\" value=\"";
								echo $db->Record['points'];
								echo "\" size=\"20\" /></td></tr><tr><td align=\"right\">真实姓名： </td><td><input  name=\"name\" type=\"text\" value=\"";
								echo $db->Record['name'];
								echo "\" size=\"20\" /></td></tr><tr><td align=\"right\">性别： </td><td><select name=\"sex\"> <option   ";
								if ($db->Record['sex']=='女'){
								echo "SELECTED   ";
								}
								echo"value=\"女\">女</option>  <option   ";
								if ($db->Record['sex']=='男'){
								echo "SELECTED   ";
								}
								echo "value=\"男\">男</option> </select></td></tr><tr><td align=\"right\">区域： </td><td><input  name=\"place\" type=\"text\" value=\"";
								if ($db->Record['place']==3){
									echo "上海";
								}else if($db->Record['place']==4){
									echo "泸州";
								}else if($db->Record['place']==5){
									echo "唐山";
								}else if($db->Record['place']==6){
									echo "南宁";
								}else if($db->Record['place']==7){
									echo "广州";
								}else{
									echo $db->Record['place'];
								}
								echo "\" size=\"20\" /></td></tr><tr align=\"center\">\r\n    <td colspan=\"2\"><input type=\"submit\" name=\"Submit_edit\" value=\"确定修改\" ></td>\r\n  </tr>\r\n</form>\r\n</table>\r\n";
				}
}

include( "inc/header.php" );
login_check( );
echo "<body>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <tr>\r\n    <td><a href=\"Admin_Member.php\"> 会员管理</a> ｜ <a href=\"Admin_Member.php?Action=add\">添加新会员</a></td>\r\n  </tr>\r\n</table>\r\n<br>\r\n";
switch ( $_GET['Action'] )
{
case "add" :
				echo "<script language=\"javascript\" src=\"inc/js.js\"></script><table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\"><form action=\"Admin_Member.php?Action=adds\" method=\"post\" onSubmit=\"return Validator.Validate(this,3)\"><input name=\"id\" type=\"hidden\" value=\"\" /><tr><td width=\"15%\" align=\"right\">会员账号：</td><td> <input name=\"user\" type=\"text\" value=\"\" size=\"20\" dataType=\"LimitB\" min=\"3\" max=\"20\" msg=\"用户名必须在3,20个字节之内\"/></td></tr><tr><td align=\"right\"> 密码：</td><td><input  name=\"password\" type=\"password\" value=\"\" size=\"40\" dataType=\"LimitB\" min=\"6\" max=\"20\" msg=\"密码必须在6,20个字节之内\" /></td></tr>  <tr><td align=\"right\">重复密码： </td><td><input  name=\"password2\" type=\"password\" value=\"\" size=\"40\" dataType=\"Repeat\" to=\"password\" msg=\"两次输入的密码不一致\" /></td></tr> <tr><td align=\"right\">邮箱地址： </td><td><input  name=\"email\" type=\"text\" value=\"\" size=\"40\" /></td></tr><tr><td align=\"right\">积分： </td><td><input  name=\"points\" type=\"text\" value=\"\" size=\"20\" /></td></tr><tr><td align=\"right\">真实姓名： </td><td><input  name=\"name\" type=\"text\" value=\"\" size=\"20\" /></td></tr> <tr><td align=\"right\">性别： </td><td> <select name=\"sex\">  <option  SELECTED>性别</option>   <option value=\"女\">女</option>  <option  value=\"男\">男</option> </select></td></tr>  <tr><td align=\"right\">区域： </td><td><input  name=\"place\" type=\"text\" value=\"\" size=\"20\" /></td></tr>
				
				<tr align=\"center\"><td colspan=\"2\"><input type=\"submit\" name=\"Submit_edit\" value=\"确定添加\" ></td></tr></form></table>";
				break;
case "adds" :
				if ( function_exists( "date_default_timezone_set" ) )
				{
								date_default_timezone_set( "Hongkong" );
				}
				@$lastime = @date( "Y-m-d H-i-s" );
				@$GLOBALS['_POST']['password'] = md5( @md5( $_POST['password'] ) );
				$db->query( "INSERT INTO tun2_member (user,password,email,points,name,sex,place) VALUES \r\n\t\t\t\t\t('".$_POST['user']."','{$_POST['password']}','{$_POST['email']}','{$_POST['points']}','{$_POST['name']}','{$_POST['sex']}','{$_POST['place']}')" );
				addlog( "添加会员", $_SESSION['user_name'] );
				admin_showerr( "<li>添加会员成功</li>", "Admin_Member.php", 1 );
				break;
case "edits" :
				edits( );
				break;
case "edit" :
				if ( $_POST['password2'] != $_POST['password'] )
				{
								echo "<script>alert(\"两次输入密码不一致,请重新输入\");</script>";
								work_back( "<br>正在返回上一页", "Admin_Member.php?Action=edits&id=".$_POST['id'] );
								exit( );
				}
				@$GLOBALS['_POST'][password] = md5( @md5( $_POST[password] ) );
				$db->query( "UPDATE tun2_member SET user='".$_POST['user']."',password='{$_POST['password']}',email='{$_POST['email']}',points='{$_POST['points']}',name='{$_POST['name']}',sex='{$_POST['sex']}',place='{$_POST['place']}' WHERE id={$_POST['id']}" );
				addlog( "修改会员", $_SESSION['user_name'] );
				admin_showerr( "<li>修改会员成功</li>", "Admin_Member.php", 1 );
				break;
case "del" :
				$db->query( "DELETE FROM tun2_member WHERE id=".$_GET['id'] );
				addlog( "删除会员", $_SESSION['user_name'] );
				admin_showerr( "<li>删除会员成功</li>", "Admin_Member.php", 1 );
				break;
default :
				@$intPerpage = 20;
				if ( $_GET['PB_page'] )
				{
								$offset = ( $_GET['PB_page'] - 1 ) * $intPerpage;
				}
				else
				{
								$offset = 0;
				}
				if ( $_GET['keyword'] != "" )
				{
								$strSql = "SELECT * FROM tun2_member WHERE place like '%".trim( $_GET['keyword'] )."%' or points like '%".trim( $_GET['keyword'] )."%' or user like '%".trim( $_GET['keyword'] )."%' or name like '%".trim( $_GET['keyword'] )."%'";
								$execc = "SELECT id FROM tun2_member WHERE place like '%".trim( $_GET['keyword'] )."%' or points like '%".trim( $_GET['keyword'] )."%' or user like '%".trim( $_GET['keyword'] )."%' or name like '%".trim( $_GET['keyword'] )."%'";
				}
				else
				{
								$strSql = "SELECT * FROM tun2_member";
								$execc = "SELECT id FROM tun2_member";
				}
				if ( isset( $_GET['Attribute'] ) )
				{
								$strSql .= " where ".$_GET['Attribute']."=1";
								$execc .= " where ".$_GET['Attribute']."=1";
				}
				if ( empty( $_GET['Sorting'] ) )
				{
								$strSql .= " Order by id desc limit ".$offset.",{$intPerpage}";
				}
				else
				{
								$strSql .= " Order by ".$_GET['Sorting']." desc limit {$offset},{$intPerpage}";
				}
				$resultc = mysql_query( $execc );
				$intNum = mysql_num_rows( $resultc );
				$db->query( $strSql );
				echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <tr width=\"10%\" >\r\n<form action=\"Admin_Member.php\" method=\"get\"> \r\n   <td align=\"right\"> \r\n<strong>会员搜索</strong>：</td>\r\n   <td width=\"44%\"><input name=\"keyword\" type=\"text\" style=\"width: 200px\" />\r\n     <input name=\"Submit\" type=\"submit\" id=\"Submit\" value=\"开始搜索\"></td>\r\n</form>\r\n   <td><strong>查看方式</strong>:       \r\n     <a href=\"Admin_Member.php?Sorting=id\">会员ID</a> |  \r\n      <a href=\"Admin_Member.php?Sorting=points\">积分</a> | \r\n <a href=\"Admin_Member.php?Sorting=place\">地区</a> | \r\n    <a href=\"Admin_Member.php?Sorting=sex\">性别</a></td>\r\n  </tr>\r\n</table>\r\n<br />\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n<form  name=\"forms\" action=\"Admin_Member.php\" method=\"post\">\r\n  <tr>\r\n   \r\n    <td width=\"5%\" align=\"center\"><strong>ID</strong></td>\r\n    <td align=\"center\"><strong>会员账号</strong></td>\r\n    <td width=\"10%\" align=\"center\"><strong>真实姓名</strong></td>\r\n   \r\n    <td width=\"5%\" align=\"center\"><strong>性别</strong></td>\r\n  <td width=\"10%\" align=\"center\"><strong>积分</strong></td>   <td width=\"10%\" align=\"center\"><strong>地区</strong></td>\r\n       <td width=\"12%\" align=\"center\"><strong>操作</strong></td>\r\n  </tr>\r\n";
				while ( $db->next_record( ) )
				{
								echo "  <tr onmouseover=\"this.bgColor='#D3EDFC'\" onmouseout=\"this.bgColor='#eff7fd'\">\r\n   <td align=\"center\">";
								echo $db->Record['id'];
								echo "</td>\r\n    <td>";
								echo $db->Record['user'];
								echo "</td>\r\n    <td align=\"center\">";
								echo $db->Record['name'];
								echo "</td>\r\n    <td  align=\"center\">\r\n\t";
								echo $db->Record['sex'];
								echo "</td>\r\n    <td  align=\"center\">\r\n\t";
								echo $db->Record['points'];
								echo "</td>\r\n  <td  align=\"center\">\r\n\t";
								if ($db->Record['place']==3){
									echo "上海";
								}else if($db->Record['place']==4){
									echo "泸州";
								}else if($db->Record['place']==5){
									echo "唐山";
								}else if($db->Record['place']==6){
									echo "南宁";
								}else if($db->Record['place']==7){
									echo "广州";
								}
								else{
								echo $db->Record['place'];
								}
								echo "</td>\r\n     <td align=\"center\"><a href=\"Admin_Member.php?Action=edits&id=";
								echo $db->Record['id'];
								echo "\">修改</a> ｜<a href=\"Admin_Member.php?Action=del&id=";
								echo $db->Record['id'];
								echo "\">删除</a></td>\r\n  </tr>\r\n";
				}
				echo "  \r\n</form>\r\n  <tr>\r\n    <td colspan=\"9\">";
				require_once( "../inc/class.page.php" );
				class mypage extends page
				{

								public function show( )
								{
												$_showpage = "<div class=\"pagenavi\" id=\"lopage\">";
												$_showpage .= $this->first_page( )." ";
												$_showpage .= $this->nowbar( "", "curr" );
												$_showpage .= "<span class=\"break\">...</span>";
												$_showpage .= $this->last_page( );
												$_showpage .= "   (总计<span class=\"num\">".$this->totalpage."</span>页 <span class=\"num\">".$this->total."</span>条记录)</div>";
												$_showpage .= "</div>";
												return $_showpage;
								}

				}

				$page = new mypage( array(
								"total" => $intNum,
								"perpage" => $intPerpage
				) );
				echo $page->show( );
}
echo "</td>\r\n  </tr>\r\n</table>\r\n</body>\r\n</html>";

?>
